package com.ansion.commonchat.contact.adapter;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;

import com.ansion.adapter.ITurboItem;
import com.ansion.adapter.TurboAdapter;
import com.ansion.baseui.base.text.SubHeadingTextView;
import com.ansion.commonchat.R;
import com.ansion.commonchat.contact.bean.ContactOtherBean;
import com.ansion.commonchat.contact.listener.IOnItemClickListener;
import com.ansion.commonchat.contact.ui.ContactItemOtherType;
import com.ansion.commonchat.contact.ui.ContactItemType;

/**
 * 联系人 群组，公众号，助手
 */
public class ContactOtherItem implements ITurboItem<ContactOtherItem.VH> {

    private IOnItemClickListener listener;

    @Override
    public int getType() {
        return ContactItemType.ItemTypeOther;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.contact_item_other;
    }


    public void addOnItemClickListener(IOnItemClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    public VH getViewHolder(View v) {
        return new VH(v);
    }

    class VH extends TurboAdapter.ViewHolder<ContactOtherBean> {

        AppCompatImageView mIvIcon;
        SubHeadingTextView mIvTitle;

        public VH(View itemView) {
            super(itemView);
            mIvIcon = itemView.findViewById(R.id.contact_item_other_icon);
            mIvTitle = itemView.findViewById(R.id.contact_item_other_title);
        }

        @Override
        public void bindView(ContactOtherBean otherBean, int position) {
            int otherType = 0;
            otherType = otherBean.otherType;
            String title = otherBean.getTitle();
            mIvTitle.setText(title);

            mIvIcon.setImageDrawable(otherBean.getIcon());
            int finalOtherType = otherType;
            itemView.setOnClickListener(v -> {
                if (listener == null) {
                    return;
                }
                if (finalOtherType == ContactItemOtherType.TypeFileAssistant && otherBean.getUserModel() != null) {
                    listener.onItemClick(otherBean.getUserModel());
                } else if (finalOtherType == ContactItemOtherType.TypeGroupChat) {
                    listener.onRouteGroupChat();
                } else if (finalOtherType == ContactItemOtherType.TypeOfficialAccount) {
                    listener.onRouteOAList();
                }
            });
        }
    }
}
